﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace NSATBPortal
{
    public partial class MachinesHome : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void TestMachinesGrid_RowEditing(object sender, GridViewEditEventArgs e)
        {
            int iIndex = e.NewEditIndex;

            string sRecID = TestMachinesGrid.DataKeys[iIndex].Value.ToString();
            string sRecAddress = TestMachinesGrid.Rows[iIndex].Cells[3].Text;
            string sRecIsVirtual = TestMachinesGrid.Rows[iIndex].Cells[4].Text;
            string sRecVMName = TestMachinesGrid.Rows[iIndex].Cells[5].Text;
            if (sRecVMName == "&nbsp;" || sRecVMName.Trim().Length == 0)
                sRecVMName = "NULL";
            string sRecVMMaxGuests = TestMachinesGrid.Rows[iIndex].Cells[6].Text;
            if (sRecVMMaxGuests == "&nbsp;" || sRecVMMaxGuests.Trim().Length == 0)
                sRecVMMaxGuests = "0";
            string sRecDetails = TestMachinesGrid.Rows[iIndex].Cells[7].Text;
            if (sRecDetails == "&nbsp;" || sRecDetails.Trim().Length == 0)
                sRecDetails = "NULL";
            string sRecActive = TestMachinesGrid.Rows[iIndex].Cells[1].Text;

            Response.Redirect("MachinesEdit.aspx?Op=Edit&ID=" + sRecID.Trim()
                            + "&Address=" + Server.UrlEncode(sRecAddress)
                            + "&IsVirtual=" + sRecIsVirtual
                            + "&VMName=" + Server.UrlEncode(sRecVMName)
                            + "&VMMaxGuests=" + sRecVMMaxGuests
                            + "&Details=" + Server.UrlEncode(sRecDetails) 
                            + "&Active=" + sRecActive);
        }
        protected void TestMachinesGrid_Init(object sender, EventArgs e)
        {
            DataTable dtResults;
            using (ATBSchemaDB objATBDB = new ATBSchemaDB())
            {
                dtResults = objATBDB.GetTestMachinesList();
            }

            TestMachinesGrid.DataSource = dtResults;
            TestMachinesGrid.DataBind();
        }
    }
}